pub mod admin;
pub mod const_val;
pub mod guest;
pub mod router;

use super::boot::err::MyError;
use actix_web::HttpResponse;
use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ResponseBean {
    pub code: i32,
    pub msg: String,
    pub bundle: Option<Value>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MemberBean {
    pub id: i32,
    pub pid: i32,
    pub tid: i32,
    pub name: String,
    pub powers: Vec<i32>,
}

pub fn resp_ok<T>(code: i32, msg: &str, bundle: T) -> Result<HttpResponse, MyError>
where
    T: Serialize,
{
    Ok(HttpResponse::Ok().json(ResponseBean {
        code,
        msg: msg.to_string(),
        bundle: serde_json::to_value(bundle).ok(),
    }))
}

pub fn resp_err(code: i32, msg: &str) -> Result<HttpResponse, MyError> {
    Ok(HttpResponse::Ok().json(ResponseBean {
        code,
        msg: msg.to_string(),
        bundle: None,
    }))
}
